#include "OgreCgProgramFactory.h"
#include "OgreString.h"
#include "OgreCgProgram.h"

namespace Ogre
{
	String CgProgramFactory::sLanguageName = "cg";

	CgProgramFactory::CgProgramFactory()
	{
		mCgContext = cgCreateContext();
		checkForCgError("CgProgramFactory::CgProgramFactory",
			"Unable to create initial Cg context: ", mCgContext);
	}

	CgProgramFactory::~CgProgramFactory()
	{
		cgDestroyContext(mCgContext);

		checkForCgError("CgProgramFactory::~CgProgramFactory",
			"Unable to destroy Cg context: ", mCgContext);
	}

	const String& CgProgramFactory::getLanguage(void) const
	{
		return sLanguageName;
	}

	HighLevelGpuProgram* CgProgramFactory::create(ResourceManager* creator,
		const String& name, ResourceHandle handle,
		const String& group, bool isManual, ManualResourceLoader* loader)
	{
		return OGRE_NEW CgProgram(creator, name, handle, group, isManual, loader, mCgContext);
	}

	void CgProgramFactory::destroy(HighLevelGpuProgram* prog)
	{
		OGRE_DELETE prog;
	}
}
